/*
 *      Created on: March 9, 2011
 *      Author: topcoder
 */
#include <VolumeUnit.h>
#include <sstream>

const unsigned int TSP_TOBASE = 1;
const unsigned int TBSP_TOBASE = TSP_TOBASE * 3;
const unsigned int OZ_TOBASE = TBSP_TOBASE * 2;

static VolumeUnit volumeArray[] = {TSP,TBSP,OZ};
const unsigned int numOfVolumeUnit = sizeof(volumeArray)/sizeof(VolumeUnit);

VolumeUnit& VolumeUnit::getOz()
{
    static VolumeUnit oz(OZ_TOBASE, "OZ");    
    return oz;
}
VolumeUnit& VolumeUnit::getTsp()
{
    static VolumeUnit tsp(TSP_TOBASE, "TSP");
    return tsp;
}
VolumeUnit& VolumeUnit::getTbsp()
{
    static VolumeUnit tbsp(TBSP_TOBASE, "TBSP");
    return tbsp;
}

VolumeUnit::VolumeUnit(unsigned int ratio, string name):Unit(ratio, name)
{
}

string VolumeUnit::print(unsigned long quantity, const VolumeUnit& unit)
{
    int loop = numOfVolumeUnit;
    ostringstream tempString;

    while(loop--)
    {
        if(volumeArray[loop] <= unit)
        {
            tempString << volumeArray[loop].outputFormat(quantity);
            quantity = volumeArray[loop].getRemainder(quantity);
        }
    }
    return tempString.str();    
}
